package com.stylefeng.guns.rest.common;

/**
 * @ClassName CurrentUser
 * Created by zghgchao 2019/8/2 23:05
 **/
public class CurrentUser {


    /***
     * 不建议将 UserInfoModel放到ThreadLocal中，当创建过多threadLocal时，JVM的内存可能撑不住
     */

    /*// 线程绑定的存储空间 (将ThreadLoad当作session使用)
    private static final ThreadLocal<UserInfoModel> threadLocal = new ThreadLocal<>();

    // 将用户信息存入存储空间
    public static void saveUserInfo(UserInfoModel model){
        threadLocal.set(model);
    }

    // 将用户信息取出
    public static UserInfoModel getCurrentUser(){
        return threadLocal.get();
    }*/

    private static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    // 将用户信息存入存储空间
    public static void saveUserId(String userId){
        threadLocal.set(userId);
    }

    // 将用户信息取出
    public static String getCurrentUser(){
        return threadLocal.get();
    }


}
